﻿// 项目：	Guan.CMS.Domain - Guan.CMS
// 文件名：	Class1.cs
// 
// 修改时间：2013-03-08 22:03
// 修改人：	Cooclsee

using Guan.CMS.CommandProcessor.Command;
using Guan.CMS.Data.Infrastructure;
using Guan.CMS.Data.Repositories;
using Guan.CMS.Domain.Commands.Account;

namespace Guan.CMS.Domain.Handlers.Account
{
    public class ChangePasswordHandler : ICommandHandler<ChangePasswordCommand>
    {
        private readonly IUserRepository _userRepository;
        private readonly IUnitOfWork _unitOfWork;
        public ChangePasswordHandler(IUserRepository userRepository, IUnitOfWork unitOfWork)
        {
            this._userRepository = userRepository;
            this._unitOfWork = unitOfWork;
        }
        public ICommandResult Execute(ChangePasswordCommand command)
        {
            var user = this._userRepository.GetById(command.UserId);
            user.Password = command.NewPassword;
            this._userRepository.Update(user);
            this._unitOfWork.Commit();
            return new CommandResult(true);
        }
    }
}